﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace PageOffice6_Net_Core.Views.InsertSeal.PDF
{
    [Route("InsertSeal/PDF")]
    public class PDFController : Controller
    {

        private readonly IWebHostEnvironment _webHostEnvironment;

        public PDFController(IWebHostEnvironment webHostEnvironment)
        {
            _webHostEnvironment = webHostEnvironment;
        }

        public IActionResult Index()
        {
            return View();
        }

        [HttpGet("AddSeal1")]
        public IActionResult AddSeal1()
        {
            string folderName = "AddSeal1";

            PageOfficeNetCore.PDFCtrl pdfCtrl = new PageOfficeNetCore.PDFCtrl(Request);
            pdfCtrl.WebOpen(folderName + "/test.pdf");
            ViewBag.pdfCtrl = pdfCtrl.GetHtml();
            return View("~/Views/InsertSeal/PDF/AddSeal1.cshtml");

        }


        [HttpGet("AddSeal2")]
        public IActionResult AddSeal2()
        {
            string folderName = "AddSeal2";

            PageOfficeNetCore.PDFCtrl pdfCtrl = new PageOfficeNetCore.PDFCtrl(Request);
            pdfCtrl.WebOpen(folderName + "/test.pdf");
            ViewBag.pdfCtrl = pdfCtrl.GetHtml();
            return View("~/Views/InsertSeal/PDF/AddSeal2.cshtml");

        }


        [HttpGet("AddSeal3")]
        public IActionResult AddSeal3()
        {
            string folderName = "AddSeal3";

            PageOfficeNetCore.PDFCtrl pdfCtrl = new PageOfficeNetCore.PDFCtrl(Request);
            pdfCtrl.WebOpen(folderName + "/hetong.pdf");
            ViewBag.pdfCtrl = pdfCtrl.GetHtml();
            return View("~/Views/InsertSeal/PDF/AddSeal3.cshtml");

        }


        [HttpGet("DeleteSeal")]
        public IActionResult DeleteSeal()
        {
            string folderName = "DeleteSeal";

            PageOfficeNetCore.PDFCtrl pdfCtrl = new PageOfficeNetCore.PDFCtrl(Request);
            pdfCtrl.WebOpen(folderName + "/test.pdf");
            ViewBag.pdfCtrl = pdfCtrl.GetHtml();
            return View("~/Views/InsertSeal/PDF/DeleteSeal.cshtml");

        }

        [HttpGet("AddSign1")]
        public IActionResult AddSign1()
        {
            string folderName = "AddSign1";

            PageOfficeNetCore.PDFCtrl pdfCtrl = new PageOfficeNetCore.PDFCtrl(Request);
            pdfCtrl.WebOpen(folderName + "/test.pdf");
            ViewBag.pdfCtrl = pdfCtrl.GetHtml();
            return View("~/Views/InsertSeal/PDF/AddSign1.cshtml");

        }


        [HttpPost("SaveFile")]
        public async Task<ActionResult> SaveFile(String folderName)
        {
            Console.WriteLine(folderName);
            PageOfficeNetCore.FileSaver fs = new PageOfficeNetCore.FileSaver(Request, Response);
			await fs.LoadAsync();

			string webRootPath = _webHostEnvironment.WebRootPath;
            fs.SaveToFile(webRootPath + "/InsertSeal/PDF/" + folderName + "/" + fs.FileName);
            return fs.Close();

        }
    }
}
